<?php
require_once 'Zend/Controller/Action.php';
class Administrator_LogController extends Zend_Controller_Action
{
	public function init()
    {
        $member=new CMember();
        if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName()))
        {
            $this->_redirect(MY_URL.'/administrator-auth-login');
        }
    	$memberArray = $member->getUserDetails(array('uid' => $_COOKIE[COOKIE_PRE.'uid']));
    	if($_COOKIE[COOKIE_PRE.'uid']=='1'){
		} else {
        	$strarray = explode(",", $memberArray[0]['menuflag']);
        	if (!in_array('6', $strarray)) {
        		exit('no priviage');
        	}
		}
    }

    public function preDispatch()
    {
        $this->getHelper ('layout')->setLayout('framelayout');
        $this->view->addHelperPath(MY_ROOT.'/vhelpers');
        Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');
    }
    
    public function indexAction()
    {
    	
    }
    
    public function productAction()
    {
    	$productLog = new CProductlog();
    	$type = $this->getRequest()->getParam('type');
    	$page = $this->getRequest()->getParam('page');
    	
    	$page = intval($page);
    	$pageNum = 5;
    	
    	$list = $productLog->getList($type, $page, $pageNum);
    	$pageCount = $productLog->getPageCount($type, $pageNum);
    	$pageString = CPage::divPages($pageCount, $page, ROOT_PATH."/administrator-log-product?type=" . $type . '&');
    	
    	$member = new CMember();
    	$product = new CItem();
    	    	
    	$this->view->member = $member;
    	$this->view->product = $product;
    	$this->view->list = $list;
    	$this->view->pageString = $pageString;
    	$this->view->pageCount = $pageCount;
    	$this->view->type = $type;
    }
    
    public function productdetailAction()
    {
    	$productLog = new CProductlog();
    	$type = $this->getRequest()->getParam('type');
    	$page = $this->getRequest()->getParam('page');
    	
    	$page = intval($page);
    	$pageNum = 5;
    	
    	if ($type == 'uid') {    		
    		$uid = $this->getRequest()->getParam('uid');
    		$param = 'uid=' . $uid;
    		$list = $productLog->getList('', $page, $pageNum, $uid, '');
    		$pageCount = $productLog->getPageCount('', $pageNum, $uid, '');
    	} elseif ($type == 'ip') {
    		$ip = $this->getRequest()->getParam('ip');
    		$ip = stripslashes($ip);
    		if ($ip == '\'\'') {
    			$ip = '1';
    		}
    		$param = 'ip=' . $ip;    		
    		$list = $productLog->getList('', $page, $pageNum, '', $ip);
    		$pageCount = $productLog->getPageCount('', $pageNum, '', $ip);
    	}
    	$member = new CMember();
    	$product = new CItem();
    	$pageString = CPage::divPages($pageCount, $page, ROOT_PATH."/administrator-log-productdetail?type=" . $type . '&' . $param);
    	$this->view->member = $member;
    	$this->view->product = $product;
    	$this->view->list = $list;
    	$this->view->pageString = $pageString;
    	$this->view->pageCount = $pageCount;
    }
    
    public function orderAction()
    {
    	$orderLog = new COrderlog();
    	$page = $this->getRequest()->getParam('page');
    	
    	$page = intval($page);
    	$pageNum = 5;
    	
    	$list = $orderLog->getList($page, $pageNum);
    	$pageCount = $orderLog->getPageCount($pageNum);
    	
    	$member = new CMember();
    	$product = new CItem();
    	$pageString = CPage::divPages($pageCount, $page, ROOT_PATH."/administrator-log-order?");
    	$this->view->member = $member;
    	$this->view->product = $product;
    	$this->view->list = $list;
    	$this->view->pageString = $pageString;
    	$this->view->pageCount = $pageCount;
    }
    
    public function orderdetailAction()
    {
    	$orderLog = new COrderlog();
    	$id = $this->getRequest()->getParam('id');
    	$id = intval($id);
    	
    	$order = $orderLog->find($id)->current();
    	$member = new CMember();
    	$product = new CItem();
    	
    	$itemArray=unserialize(stripslashes($order->order_str));
        $this->view->assign('itemArray',$itemArray);
    	$this->view->member = $member;
    	$this->view->product = $product;
    	$this->view->order = $order;
    }
}